from multiprocessing import Pool
import os, time, random
from bestbuy_spider import BestbuySpider
class Manager:
  def __init__(self,):
    self.spider_list = []

  def add_spider(self, spider):
    self.spider_list.append(spider)

  def run(self):
    while(True):
      print("current time : %s" % time.ctime())
      with Pool() as pool:
        pool.map(self.run_spider, self.spider_list)

      time.sleep(5)

  def run_spider(self, spider):
    res = spider.getData()
    print(res['price'])

if __name__=='__main__':
  manager = Manager()
  url = 'https://www.bestbuy.com/site/apple-macbook-air-13-3-display-intel-core-i5-8gb-memory-128gb-flash-storage-latest-model-silver/5465502.p?skuId=5465502'
  manager.add_spider(BestbuySpider(url))
  manager.add_spider(BestbuySpider('https://www.bestbuy.com/site/apple-magic-mouse-2-silver/4639400.p?skuId=4639400'))
  manager.add_spider(BestbuySpider('https://www.bestbuy.com/site/apple-magic-keyboard-with-numeric-keypad/5822302.p?skuId=5822302'))
  manager.run()